// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.warehouse.viewers.action;

import java.util.ArrayList;
import java.util.List;

import org.dengues.core.actions.AbstractAction;
import org.dengues.core.resource.DenguesProject;
import org.dengues.core.resource.DenguesProjectFactory;
import org.dengues.core.warehouse.ENodeCategoryName;
import org.dengues.ui.datasource.ProjectConnsSelectDialog;
import org.eclipse.swt.widgets.Display;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf Qiang.Zhang.Adolf@gmail.com 2008-1-22 qiang.zhang $
 * 
 */
public class ImportConnsFromOthersAction extends AbstractAction {

    /**
     * Qiang.Zhang.Adolf@gmail.com ImportConnectivityFromOthers constructor comment.
     */
    public ImportConnsFromOthersAction() {
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com ImportConnectivityFromOthers constructor comment.
     * 
     * @param name
     */
    public ImportConnsFromOthersAction(String name) {
        super(name);
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
    @Override
    public void run() {
        DenguesProject[] readProjects = DenguesProjectFactory.readProjects();
        List<DenguesProject> othersProj = new ArrayList<DenguesProject>();
        String curproj = DenguesProjectFactory.getDenguesProject().getName();
        for (DenguesProject denguesProject : readProjects) {
            if (!denguesProject.getName().equals(curproj)) {
                othersProj.add(denguesProject);
            }
        }
        ProjectConnsSelectDialog dialog = new ProjectConnsSelectDialog(Display.getDefault().getActiveShell(), othersProj);
        dialog.open();
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.actions.AbstractAction#getLevel()
     */
    @Override
    public int getLevel() {
        return 22;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.actions.AbstractAction#computeEnable()
     */
    @Override
    protected boolean computeEnable() {
        boolean isEnable = false;
        if (pnodes != null && pnodes.size() == 1) {
            isEnable = ENodeCategoryName.DATASOURCE == pnodes.get(0).getCategoryName();
        }
        return isEnable;
    }

}
